package com.example.demo.servlet;
import com.example.demo.dao.OrdersDao;
import com.example.demo.entity.OrdersVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/addorder")
public class AddOrdersServlet extends HttpServlet{
    protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
        OrdersVo ordersVo = new OrdersVo();
        Integer orderId = Integer.parseInt(request.getParameter("ordersid"));
        Integer userid = Integer.parseInt(request.getParameter("userid"));
        String ordersstatus = request.getParameter("ordersstatus");
        Integer totalprice = Integer.parseInt(request.getParameter("totalprice"));
        ordersVo.setOrdersid(orderId);
        ordersVo.setUserid(userid);
        ordersVo.setOrdersstatus(ordersstatus);
        ordersVo.setTotalprice(totalprice);
        try {
            new OrdersDao().saveOrders(ordersVo);
            request.getRequestDispatcher("").forward(request,response);
        }catch (Exception e){
            e.printStackTrace();
            throw new
                    RuntimeException(e);
        }
    }
}
